var ValidateArticles = function () {
	return {
		init:function() {
			validator=$('.form-horizontal').validate({
				errorElement: 'span', //default input error message container
				errorClass: 'help-block', // default input error message class
				focusInvalid: false, // do not focus the last invalid input
				rules: {
					articleTitle: {
						required: true
					},
					articleKey: {
						required: true
					},
					/* articleContent: {
						required: true
					} */
				},

				messages: {
					articleTitle: {
						required: "文章标题不能为空。"
					},
					articleKey: {
						required: "文章关键字不能为空。"
					},
					/* articleContent: {
						required: "文章内容不能为空。"
					} */
				},

				invalidHandler: function (event, validator) { //display error alert on form submit
					$('.alert-danger', $('.role-form')).show();
				},

				highlight: function (element) { // hightlight error inputs
					$(element)
						.closest('.form-group').addClass('has-error'); // set error class to the control group
				},

				success: function (label) {
					label.closest('.form-group').removeClass('has-error');
					label.remove();
				},

				errorPlacement: function (error, element) {
					error.insertAfter(element.closest(':input'));
				},

				submitHandler: function (form) {        
					CKupdate();
					$.post(ajaxUrl,$(".form-horizontal").serialize(),  function(data) {
						if(data.status=='1'){
							layer.msg(data.info, 
								{icon: 1,time: 2000},
								function(){
									location.href=ajaxUrl;
								}
							);   	
						}else{
							layer.msg(data.info, 
								{icon: 2,time: 2000}
							);   
							return;
						}
					});           
				}
			});
			function CKupdate() {
               for (instance in CKEDITOR.instances)
                   CKEDITOR.instances[instance].updateElement();
           }
			$('.form-horizontal input').keypress(function (e) {
				if (e.which == 13) {
					if ($('.form-horizontal').validate().form()) {
						$('.form-horizontal').submit();
					}
					return false;
				}
			});
		}
    };
}();